﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using Newtonsoft.Json;
using ProjectStudy.WebService;


namespace ProjectStudy
{
    /// <summary>
    /// WebService1 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "你好，世界";
        }

        [WebMethod]
        public string HelloString(string name)
        {
            return "你好，"+name;
        }

        [WebMethod]
        public int HelloInt()
        {
            return 5;
        }

        [WebMethod]
        public bool HelloBool()
        {
            return true;
        }

        [WebMethod]
        public float HelloFloat()
        {
            return 1.11f;
        }

        [WebMethod]
        public List<int> CreateArray(int i)
        {
            List<int> list = new List<int>();
            while (i >= 0)
            {
                list.Add(i--);
            }
            return list;
        }

        [WebMethod]
        public List<Student> HelloStudent()
        {
            List<Student> list = new List<Student>();
            Student s1 = new Student();
            s1.Name = "张三";
            s1.Sex = "男";
            s1.Age = 22;

            Student s2 = new Student();
            s2.Name = "李四";
            s2.Sex = "女";
            s2.Age = 25;

            list.Add(s1);
            list.Add(s2);
            return list;
        }

        [WebMethod]
        public DataSet GetClassInfoXML()
        {
            string sql = "select * from class1";
            DataSet ds = DBAccess.ExecuteDataset(sql);
            return ds;
        }

        [WebMethod]
        public DataTable GetClassInfo()
        {
            string sql = "select * from class1";
            DataTable ds = DBAccess.ExecuteDataTable(sql);
            return ds;
        }

        [WebMethod]
        public string GetClassInfoJson()
        {
            string sql = "select * from class1";
            DataTable dt = DBAccess.ExecuteDataTable(sql);
            return JsonConvert.SerializeObject(dt);
        }
    }
}
